<template>
    <div @mouseleave="close">
        <div :class="{ header: true, white: scrollPosition <= 100 && !tabName && pathName != 'newdetail' }">
            <div class="header_con">
                <div class="logo" @click="goPage('/index')">
                    <img v-show="scrollPosition <= 100 && !tabName && pathName != 'newdetail'" :src="options.main_logo"
                        alt="">
                    <img v-show="!(scrollPosition <= 100 && !tabName && pathName != 'newdetail')" :src="options.second_logo" alt="">

                </div>
                <div class="menu">
                    <div :class="item.id" @mouseenter="(e) => getTab(e, item.id)" v-for="item in list" :key="item.id">
                        {{ item.name }}
                        <span class="line"></span>
                    </div>

                </div>
            </div>
            <div class="txt">
                <div @click="openUrl">
                    <img v-show="scrollPosition <= 100 && !tabName && pathName != 'newdetail'" src="@/assets/img/en1.png" alt="">
                    <img v-show="!(scrollPosition <= 100 && !tabName && pathName != 'newdetail')" src="@/assets/img/en2.png" alt="">
                </div>
                <span>为老百姓造一辆好车</span>
            </div>

        </div>
        <div class="right" :style="{right:tabName?'0.26042vw':0}">
                    <div v-popover:popover>
                        <img src="@/assets/img/kefu2.png" alt="">
                        <span>客服</span>
                    </div>
                    <router-link style="text-decoration: none;" :to="{ name: 'feadback' }" target="_blank">
                        <div class="feadback">
                            <img src="@/assets/img/feadback.png" alt="">
                            <span>反馈</span>
                        </div>
                    </router-link>

                    <div @click="top" class="goTop" v-show="scrollPosition > 800">
                        <img src="@/assets/img/top.png" alt="">
                        <span>回顶部</span>
                    </div>
                </div>
                <el-popover ref="popover" placement="top-end" :visible-arrow="false" trigger="hover">
                    <div class="online">
                        <img src="@/assets/img/cusicon.png" alt="">
                        <div>
                            <p>在线客服</P>
                            <span class="tel">{{ options.kf_phone }}</span>
                            <span class="onlinetime">{{ options.kf_worktime }}</span>
                            <span>{{ options.site_analytics }}</span>
                        </div>
                    </div>
                </el-popover>
        <headerMenu @close="close" :tabName="tabName" />
    </div>
</template>

<script>
import headerMenu from "@/components/headerMenu.vue"
export default {
    components: {
        headerMenu
    },
    data() {
        return {
            scrollPosition: 0,
            // list: [
            //     {
            //         name: '电动三轮车',
            //         id: 'ddsl'
            //     },
            //     {
            //         name: '电动生活',
            //         id: 'ddsh'
            //     },
            //     {
            //         name: '富贵科技',
            //         id: 'fgkj'
            //     },
            //     {
            //         name: '服务支持',
            //         id: 'fwzc'
            //     },
            //     {
            //         name: '关于我们',
            //         id: 'gywm'
            //     }
            // ],
            tabName: '',
        }
    },
    computed: {
        pathName() {
            return this.$route.name
        },
        options() {
            return this.$store.state.dataInfo
        },
        list() {
            return this.$store.state.menuList.list
        }
    },
    watch:{
        tabName(n){
            if(n){
                document.body.style.overflow = 'hidden';
               
            }else{
                document.body.style.overflow = '';
            }
        }
    },
    mounted() {
        window.addEventListener('scroll', this.handleScroll)
    },
    beforeDestroy() {
        window.removeEventListener('scroll', this.handleScroll)
    },
    methods: {
        top() {
            window.scrollTo({
                top: 0,
                behavior: 'smooth' // 平滑滚动
            });
        },
        handleScroll() {
            this.scrollPosition = window.scrollY
        },
        goPage(url) {
            if (url) {
                this.$router.push(url)
                this.$emit('close')
            }
            this.close()

        },
        getTab(e, name) {
            this.tabName = name
            const fgkj = document.querySelector(".fgkj");
            const fwzc = document.querySelector(".fwzc");
            const gywm = document.querySelector(".gywm");
            const tagRect = fgkj.getBoundingClientRect();
            const tagRect2 = fwzc.getBoundingClientRect();
            const tagRect3 = gywm.getBoundingClientRect();
            this.$store.commit('setOffset', {
                fgkj: tagRect,
                fwzc: tagRect2,
                gywm: tagRect3
            })
        },
        openUrl(){
            // window.open('http://fgcyen.woyii.com/index')
        },
        close() {
           this.tabName = ''
        }
    }
}
</script>

<style lang="scss" scoped>
.header {
    width: calc(100vw -  0.26042vw);
    height: 72px;
    padding: 0px 250px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999;
    background-color: #fff;

    .header_con {
        display: flex;
        align-items: center;
        justify-content: center;

        .logo {
            cursor: pointer;
            width: 169px;
            height: 50px;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;

            img {
                width: 100%;
                height: 100%;
            }
        }

        .menu {
            margin-left: 28px;
            display: flex;
            align-items: center;
            justify-content: center;

            >div {
                position: relative;
                padding: 0 36px;
                font-weight: 400;
                font-size: 16px;
                color: #000000;
                cursor: pointer;
                display: flex;
                align-items: center;
                flex-direction: column;
                justify-content: center;
                height: 72px;

                .line {
                    position: absolute;
                    bottom: 0;
                    width: 79px;
                    background-color: #B00D16;
                    height: 3px;
                    display: none;

                }

                &:hover .line {
                    display: block;
                }

            }
        }
    }

    .txt {
        font-weight: 400;
        font-size: 16px;
        color: #000000;
        align-items: center;
        justify-content: center;
        display: flex;

        >div {
            align-items: center;
            justify-content: center;
            display: flex;
        }

        img {
            cursor: pointer;
            width: 30px;
            height: 30px;
            margin-right: 15px;
        }
    }
}

.white {
    background-color: transparent;
    color: #fff;

    .header_con {
        .menu {
            div {
                color: #fff;
            }
        }
    }

    .txt {
        color: #fff;
    }
}
.online {
    padding: 20px 5px;
    display: flex;

    img {
        width: 40px;
        height: 40px;
        margin-right: 20px;
        flex-shrink: 0;
    }

    div {
        display: flex;
        flex-direction: column;
        font-family: MiSans;
        font-weight: 400;
        font-size: 22px;
        width: 260px;

        p {
            margin: 0;
            padding: 0;
            color: #000;
        }

        .tel {
            margin: 5px 0;
            color: #B00D16;
        }

        .go {
            margin-top: 20px;
            color: #B00D16;
            font-weight: 500;
            font-size: 18px;
            cursor: pointer;
        }
    }
}

.right {
    width: 60px;
    position: fixed;
    right: 0;
    top: 50%;
    z-index: 98;
    background-color: #fff;
    border-radius: 15px 0 0 10px;
    padding: 10px 6px 10px;
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: center;
    transition: all 0s;
    >div,
    .feadback {
        cursor: pointer;
        display: flex;
        align-items: center;
        flex-direction: column;
        justify-content: center;
        font-family: MiSans;
        font-weight: 400;
        font-size: 12px;
        color: #2c2c2c;
        margin-bottom: 15px;
        font-weight: bold;
        text-decoration: none;

        &:last-child {
            margin: 0;
        }

        &:first-child {
            img {
                width: 22px;
            }
        }

        span {
            text-decoration: none;
        }

        img {
            width: 20px;
            height: auto;
            margin-bottom: 5px;

        }
    }

    .goTop {
        margin-top: 15px !important;
    }
}

</style>